package com.crm.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @version 1.0
 * @author: CRM_SYSTEM
 * @date: 2022/3/31 19:53
 * @Description:
 */
@AllArgsConstructor
@Getter
public enum  FileTypeEnum {
    /**
     *
     */
    PICTURE(100001,"PICTURE","图片",new ArrayList<>(Collections.singletonList(".png,.jpg"))),
    VIDEO(100002,"VIDEO","视频",new ArrayList<>(Collections.singletonList(".mp3,.mp4,.mp5"))),
    SHEET(100003,"SHEET","表格",new ArrayList<>(Collections.singletonList(".xlsx,.xls"))),
    DOCUMENT(100004,"DOCUMENT","文档",new ArrayList<>(Collections.singletonList(".doc,.docx"))),
    OTHERS(100005,"OTHERS","其他",new ArrayList<>()),
    ;
    private Integer code;
    private String value;
    private String desc;
    private List<String> suffixList;


    public static FileTypeEnum getBySuffix(String suffix){
        if (StringUtils.isBlank(suffix)){
            return OTHERS;
        }

        for (FileTypeEnum fileTypeEnum : FileTypeEnum.values()) {
            if (fileTypeEnum.getSuffixList().contains(suffix)){
                return fileTypeEnum;
            }
        }
        return OTHERS;
    }

}
